<%
QString lang = httpRequest().cookie("lang");
QString tid = variant("tid").toString().isEmpty() ? tId(): variant("tid").toString();
QString menusGroupId = httpRequest().queryItemValue("menusGroupId").isEmpty()? variant("menusGroupId").toString() : httpRequest().queryItemValue("menusGroupId");
QString relation = httpRequest().queryItemValue("relation").isEmpty() ? "assigned" : httpRequest().queryItemValue("relation");
QString action = variant("action").toString();

QString relationKey ="{'menusGroupId':'" + menusGroupId + "'}";

%>
<div class="mini-fit">
<div id="relationMenuByMenusGroup<%== tid %>" name="relationMenu" class="mini-datagrid" style="width:475px;height:100%;" 
showPager="false" showEmptyText="true" multiSelect="true" onpreload="onpreload" allowSortColumn="false"
<% if (action=="edit") { %>
allowCellEdit="true" allowCellSelect="true"
<% } %>
url="/DataService/Search/<%== relation %>MenuByMenusGroup?searchMode=all&relation=<%== relation %>" sortFields="[{'field':'menuOrder'},{'field':'menuCd']"
ajaxOptions="{data:{relationKey:mini.encode(<%== relationKey %>)}}" >
  <div property="columns">
    <div type="indexcolumn" width="25"></div>
    <div type="checkcolumn" width="25"></div>
    <div visible="false" field="menuId"></div>
    <div header="<%== UI("MENUCD") %>" field="<%== "menuCd" %>" allowsort="true"></div>
    <div header="<%== lang == "zh" ? UI("MENUNAMEZH") : UI("MENUNAMEEN") %>" field="<%== lang == "zh" ? "menuNameZh" : "menuNameEn" %>" width="100%" allowsort="true"></div>  
    <% if (relation=="assigned"){ %>
    <div header="<%== UI("MENUORDER") %>" field="<%== "menuOrder" %>" allowsort="true" width="50" headerAlign="center" align="center">
         <input property="editor" class="mini-spinner"style="width:100%;"/>
    </div>
    <div type="checkboxcolumn" header="<%== UI("BREAKBOOL") %>" field="<%== "breakBool" %>" width="50" headerAlign="center"></div>
    <% } %>
  </div>
</div>
</div>
<script type="text/javascript">
  mini.parse();
  var grid = mini.get("relationMenuByMenusGroup<%== tid %>");
  var sorter = new MultiSort(grid);
  sorter.sort([{'field':'menuOrder'},{'field':'menuCd'}]);
  
  grid.on("drawcell", function (e) {
    if (e.field=="menuCd") {
          e.cellHtml = '<a href="javascript:showRecord(\'relationMenuByMenusGroup<%== tid %>\',\'<%== UI("Menu") %>\',650,500,\'/PartialService/formMenu?action=show\',[\'menuId\'])">' + e.value + '</a>';
        }
  });
</script>